package com.example.javatest;/**
 * @author wangXiao
 */

import com.example.javatest.celuemoshi.Myinterface;
import com.example.javatest.zerenlian.ChainPatternDemo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description: 策略模式
 * @Author wangXiao
 * @Date 2024/3/20 
 **/

@RestController
@RequestMapping("/testCelue")
@Slf4j
@Api("celueController相关的api")
public class DesignTestController {

    @Resource
    List<Myinterface> interFacelists;

    Map<String, Myinterface> interFaceMap = new ConcurrentHashMap<>();
    @Resource
    ChainPatternDemo chainPatternDemo;

    public DesignTestController(Map<String, Myinterface> interFaceMap1) {
        this.interFaceMap.clear();
        interFaceMap1.forEach((k, v) -> {
            //String key = k.substring(0, k.length() - "ChannelStrategy".length());
            this.interFaceMap.put(k, v);
        });
    }

    public Myinterface getResource(String payType) {
        return interFaceMap.get(payType);
    }

    @PostMapping("/testcelue")
    public void testcelue() {
        Myinterface myinterfaceImpl = getResource("myinterfaceA");
        myinterfaceImpl.sayhello();
    }

    @PostMapping("/testzerenlian")
    public void testzerenlian() {
        chainPatternDemo.exec();
    }
}
